<?php

use think\migration\Migrator;

class CreateCategoryTable extends Migrator
{

    const TBL_NAME = 'category';
    const RELATED_TBL_NAME = 'user';


    public function change()
    {
        // create the table
        $table  =  $this->table(addTablePrefix(self::TBL_NAME),[
                'engine'=>'InnoDB',
                'comment' => '分类表',
                'signed' => false
            ]);
        $table
            ->addColumn('name', 'string',array('limit'  =>  17,'default'=>'','comment'=>'分类名称'))
            ->addColumn('desc', 'string',array('limit'  =>  255,'default'=>'','comment'=>'分类描述'))
            ->addColumn('user_id', 'integer',array('signed' => false,'null'=>true,'comment'=>'创建者'))
            ->addColumn('create_time', 'integer',array('signed' => false, 'default'=>0,'comment'=>'创建时间'))
            ->addColumn('update_time', 'integer',array('signed' => false, 'default'=>0,'comment'=>'修改时间'))
            ->addIndex(array('name'), array('unique'  =>  true))
            ->addIndex(array('create_time'))
            ->addForeignKey('user_id', addTablePrefix(self::RELATED_TBL_NAME), 'id', ['delete'=> 'SET_NULL', 'update'=> 'NO_ACTION'])
            ->create();
    }




}
